/*
    Borealis Library
    A library of commonly used hydrological modeling building blocks

    Copyright (C) 2008  Chris Marsh

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include "include\borealis\RegexTokenizer.hpp"

namespace Borealis
{


	void RegexTokenizer::SetExpression( std::string exp, bool case_sensitive )
	{
		try
		{
			if(!case_sensitive)
				re.assign(exp,boost::regex_constants::icase);
			else
				re.assign(exp);
		}
		catch ( ... )
		{
			throw std::runtime_error("Invalid regular expression");
		}

	}

	std::string RegexTokenizer::GetExpression()
	{

		return re.expression();
	}



	RegexTokenizer::RegexTokenizer() :
		FLOAT_REGEX("-?[0-9]+\\.?[0-9]*")
	{

	}

	RegexTokenizer::RegexTokenizer( std::string regex, bool case_senstive /*= true*/ ) :
		FLOAT_REGEX("-?[0-9]+\\.?[0-9]*")
	{
		try
		{
			SetExpression(regex,case_senstive);
		}
		catch ( ... )
		{
			//nothing. don't want a zombie
		}
		
	}
	RegexTokenizer::~RegexTokenizer()
	{

	}
}